﻿Imports DTO
Public Class ChiTietPhieuThueDAO
    Public Shared Function Them(ByVal ctpt As ChiTietPhieuThue) As Integer
        ctpt.MaPhieuThue = PhieuThueDAO.LayMaxMa()
        Dim sql = "insert into CHITIETPHIEUTHUE(TenKhachHang,MaLoaiKhachHang,CMND,DiaChi,MaPhieuThue) values('" + ctpt.TenKhachHang + "'," + ctpt.MaLoaiKhachHang.ToString() + ",'" + ctpt.CMND + "','" + ctpt.DiaChi + "'," + ctpt.MaPhieuThue.ToString() + ")"
        Return Dataprovider.ExecuteNonQuery(sql)
    End Function
    Public Shared Function LaySoLuongKhachTrongPhong(ByVal maphong As Integer) As Integer
        Dim sql As String = "select count(*) from CHITIETPHIEUTHUE ct,PHIEUTHUE pt where ct.MaPhieuThue=pt.MaPhieuThue and pt.MaPhong=" + maphong.ToString()
        Return Integer.Parse(Dataprovider.ExecuteScalar(sql))
    End Function
    Public Shared Function LaySoLuongLoaiKhach(ByVal maphong As Integer, ByVal makhachnuocngoai As Integer) As Integer
        Dim sql As String = " SELECT        COUNT(*) AS Expr1 FROM  (CHITIETPHIEUTHUE ct INNER JOIN    PHIEUTHUE pt ON ct.MaPhieuThue = pt.MaPhieuThue) WHERE        (ct.MaLoaiKhachHang = " + makhachnuocngoai.ToString() + ") AND (pt.MaPhong = " + maphong.ToString() + ")"

        Try
            Return Integer.Parse(Dataprovider.ExecuteScalar(sql))
        Catch ex As Exception
            Return 0
        End Try
    End Function
End Class
